package cn.hiapi.shopkeeper.jpa.order;

import cn.hiapi.basic.jpa.BasicRepository;
import cn.hiapi.shopkeeper.entity.order.ActivityOrder;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author AdinZ
 * @date 2022/12/17 13:35
 */
public interface ActivityOrderJpa extends BasicRepository<ActivityOrder,Long> {
    @Query("select count(e.id) from ActivityOrder e where e.aid=?1 and e.orderType=1 group by e.buyerId")
    List totalBuyUser(long aid);


    @Query("select sum(e.payment) from ActivityOrder e where e.aid=?1 and e.statusType=1")
    BigDecimal totalMoney(long aid);


    @Query("select sum(e.payment) from ActivityOrder e where e.shopId=?1 and e.created between ?2 and ?3 and e.statusType=1")
    BigDecimal totalMoney(long shopId, long startTime, long endTime);


    @Query("select count(e.id) from ActivityOrder e where e.shopId=?1 and e.created between ?2 and ?3  and e.orderType=1 group by e.buyerId")
    List totalBuyUser(long shopId, long startTime, long endTime);

    @Query("select sum(e.solitaire) from ActivityOrder e where e.aid=?1 and e.statusType=1")
    BigDecimal totalSumSolitaire(long aid);


    /**
     * 统计待使用 金额
     * @param shopId
     * @return
     */
    @Query("select sum(e.payment) from ActivityOrder  e where e.shopId=?1 and e.status='WAIT_USE' ")
    BigDecimal totalSumWaitUseAmount(long shopId);

    /**
     * 统计已核销订单金额
     * @param shopId
     * @return
     */
    @Query("select sum(e.payment) from ActivityOrder  e where e.shopId=?1 and e.useStatus=1 ")
    BigDecimal totalSumComplete(long shopId);
}
